package com.moju.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * DBUtil
 */
public class SqlSessionUtil {

    public static SqlSession getSqlSession(){
        SqlSession sqlSession= null;

        //需要
        try {
            InputStream ips = Resources.getResourceAsStream("mybatis-config.xml");

            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(ips);

            sqlSession  = sqlSessionFactory.openSession(true);


        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return  sqlSession;
    }


}
